//
//  BADListViewController.m
//  BAD
//
//  Created by Can on 2018/5/14.
//  Copyright © 2018年 hwd. All rights reserved.
//

#import "BADListViewController.h"
#import "BADMenuViewController.h"
#import "BADLinkViewController.h"

@interface BADListViewController ()

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation BADListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self creatView];
    
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
//    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
}

-(void)creatView
{
    CGFloat height = StatusBarHeight;

    UIImageView *imageView = [UIViewControls creatImageView:CGRectMake(0, -height, SCREENW, SCREENH + height) imageName:@"bg2018_2"];
    [self.view addSubview:imageView];
    imageView.userInteractionEnabled = YES;
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH + height) style:UITableViewStylePlain];
    [imageView addSubview:_tableView];
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.showsHorizontalScrollIndicator = NO;
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
    [_tableView setTableHeaderView:[self creatButton]];
    
    UIImageView *backImageView = [UIViewControls creatImageView:CGRectMake(SCREENW - 25*screenW_6 - 35*screenW_6, 105/2*screenW_6, 35*screenW_6, 35*screenW_6) imageName:@"close"];
    [self.view addSubview:backImageView];
    backImageView.userInteractionEnabled = YES;
    //添加点击手势（即点击图片后退出全屏）
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeView)];
    [backImageView addGestureRecognizer:tapGesture];
}

-(UIView *)creatButton
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 0)];
    
    UIImageView *bioisland = [UIViewControls creatImageView:CGRectMake((SCREENW - 405/2*screenW_6)/2, 313/2*screenW_6, 405/2*screenW_6, 72/2*screenW_6) imageName:@"logo2"];
    [view addSubview:bioisland];
    
    NSArray *titleArray = @[@"PRODUCTS",@"RETAILERS",@"CONTACT",@"BLOG",@"RECIPES"];
    
    for (int i = 0; i<titleArray.count; i++) {
        UIButton *button = [UIViewControls creatButton:CGRectMake(0, CGRectGetMaxY(bioisland.frame) + 157/2*screenW_6 + (36.02*screenW_6 + 72/2*screenW_6)*i - 36.02/2*screenW_6*(i + 1), SCREENW, 36.02*screenW_6) title:titleArray[i]];
        button.tag = i;
        [button addTarget:self action:@selector(buttonChose:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:button];
        view.frame = CGRectMake(0, 0, SCREENW, CGRectGetMaxY(button.frame) + 60*screenW_6);
    }
    
    return view;
}

-(void)closeView
{
    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:[BADMenuViewController class]]) {
            [self.navigationController popToViewController:controller animated:YES];
        }
    }
}

- (void)buttonChose:(UIButton *)btn
{
    BADLinkViewController *linkVC = [BADLinkViewController new];
    switch (btn.tag) {
        case 0:
            linkVC.strUrl = @"http://www.maxigenes.com.au/products";
            break;
        case 1:
            linkVC.strUrl = @"http://www.maxigenes.com.au/retailers";
            break;
        case 2:
            linkVC.strUrl = @"http://www.maxigenes.com.au/contact";
            break;
        case 3:
            linkVC.strUrl = @"http://www.maxigenes.com.au/blog";
            break;
        case 4:
            linkVC.strUrl = @"http://www.maxigenes.com.au/recipes";
            break;
        
        default:
            break;
    }
    [self.navigationController pushViewController:linkVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
